﻿///<reference path="../../../Scripts/jquery-1.4.1-vsdoc.js"/>
///<reference path="../utils/Utils.js"/>


function KeyManager() {

    this.bookPrefix = "book_";
    this.chapterPrefix = "chapter_";
    this.versePrefix = "verse_";

    this.GetBookKey = function (bookIndex) {
        return this.bookPrefix + bookIndex;
    }

    this.GetBookIndex = function (bookKey) {        
        return bookKey.substr(this.bookPrefix.length, bookKey.length - this.bookPrefix.length)
    }

    this.GetBookKeyFromChapterKey = function (chapterKey) {
        var i = chapterKey.lastIndexOf(".");
        return this.bookPrefix + chapterKey.substr(this.chapterPrefix.length, i - this.chapterPrefix.length)
    }

    this.GetBookKeyFromVerseKey = function (verseKey) {
        var chapterKey = this.GetChapterKeyFromVerseKey(verseKey);
        return this.GetBookKeyFromChapterKey(chapterKey);
    }

    this.GetChapterKey = function (bookIndex, chapterIndex) {
        return this.chapterPrefix + bookIndex + "." + (chapterIndex + 1);
    }

    this.GetChapterIndexFromKey = function (chapterKey) {
        var i = chapterKey.lastIndexOf(".");
        return (chapterKey.substr(i + 1, chapterKey.length - i) - 1);
    }

    this.GetChapterKeyFromVerseKey = function (verseKey) {
        var i = verseKey.lastIndexOf(".");
        return this.chapterPrefix + verseKey.substr(this.versePrefix.length, i - this.versePrefix.length)        
    }

    this.GetVerseKey = function (bookIndex, chapterIndex, verseIndex) {
        return this.versePrefix + bookIndex + "." + (chapterIndex + 1) + "." + (verseIndex + 1);
    }

    this.GetVerseIndexFromKey = function (verseKey) {
        var i = verseKey.lastIndexOf(".");
        return (verseKey.substr(i + 1, verseKey.length - i) - 1);
    }    
}
